<template>
    <div class="web_notice" v-if="visible" @click.self="closeNotice">
      <div class="notice-content" :class="{ fadeIn: visible, fadeOut: !visible }">
        <h3>网站通知</h3>
        <div class="notice-text">{{ message }}</div>
        <a @click.stop="closeNotice" class="close-button">我知道了</a>
      </div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        visible: true,
        message: '这是一个公告'
      };
    },
    methods: {
      closeNotice() {
        this.visible = false;
        setTimeout(() => {
          this.$emit('closed');
        }, 300);
      }
    },
    props: {
      msg: {
        type: String,
        default: '这是一个公告'
      }
    },
    watch: {
      msg(newVal) {
        this.message = newVal;
      }
    }
  };
  </script>
  
  <style scoped>
  .web_notice {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px; /* 增加整体的内边距 */
    box-sizing: border-box; /* 确保内边距不会影响宽度 */
  }
  
  .notice-content {
    width: 100%;
    max-width: 400px; /* 设置最大宽度以适应移动设备 */
    background: #FFF;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.3s ease;
  }
  
  .fadeIn {
    opacity: 1;
  }
  
  .fadeOut {
    opacity: 0;
  }
  
  .notice-content h3 {
    font-weight: bold;
    text-align: center;
    font-size: 24px;
  }
  
  .notice-text {
    font-size: 14px;
    margin-top: 20px;
    line-height: 24px;
    color: #666;
    text-align: justify;
  }
  
  .close-button {
    display: block;
    background: #98a3ff;
    color: #FFF;
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    line-height: 50px;
    margin: 20px auto 0;
    border-radius: 25px;
    width: 70%;
  }
  </style>